<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="库存预警">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
    </style>

    <script>
        jQuery(function () {
            fixTableOperatorButton();

            $(".close").click(function () {
                closeAll();
            });

            ajaxSelect("${baseUrl}goods/type/getAll.action","typeId","全部", function () {
                formSetVal("searchForm",{type:"${type}"});
            });
        });

        layui.use(['form', 'table'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                util = layui.util;

            renderTable();
            form.on('select(typeId)', function (data) {
                table.reload('table',{where: genSearch(),page: {curr: 1}});
            });

            form.on('select(type)', function (data) {
                table.reload('table',{where: genSearch(),page: {curr: 1}});
            });

            form.on('submit(search)', function (data) {
                table.reload('table',{where: genSearch(),page: {curr: 1}});
                return false;
            });

        });

        function renderTable() {
            layui.table.render({
                id:'table',
                elem: '#table',
                url: "${baseUrl}goods/goodsHouseWarn/listVo.action",
                where : {
                    type :"${type}",
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",templet:function (d) {return d.LAY_INDEX;}},
                    {field: 'no', width: 150, title: '编号',style:"font-size:12px;",templet: function(d){
                            return d.goodsVo.no;
                        }},
                    {field: 'name', width: 150, title: '名称',style:"font-size:12px;",templet: function(d){
                            return d.goodsVo.name;
                        }},
                    {field: 'norms', width: 150, title: '规格',style:"font-size:12px;",templet: function(d){
                            return emptyEntity(d.goodsVo.norms) ? '':d.goodsVo.norms;
                        }},
                    {width: 120, title: '单位',style:"font-size:12px;",templet: function(d){
                            return d.goodsVo.goodsUnitVoList[0].unit.name;
                        }},
                    {width: 120, title: '门店',style:"font-size:12px;",templet: function(d){
                            return d.houseVo.store.name;
                        }},
                    {width: 120, title: '仓库',style:"font-size:12px;",templet: function(d){
                            return d.houseVo.name;
                        }},
                    {field: 'stockNum', width: 120, title: '库存数量',style:"font-size:12px;"},
                    {field: 'min', width: 120, title: '最低库存量',style:"font-size:12px;"},
                    {field: 'max', width: 120, title: '最高库存量',style:"font-size:12px;"},
                    {width: 120, title: '预警值',style:"font-size:12px;color:#FF5722;",templet: function(d){
                            if (d.stockNum < d.min) {
                                return '<' + (d.min-d.stockNum);
                            } else {
                                return '>' + (d.stockNum-d.max);
                            }
                        }},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                }
            });
        }

        function genSearch() {
            let json = getFormJson($("#searchForm"));
            return json;
        }
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="searchForm" lay-filter="searchForm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">商品分类</label>
                    <div class="layui-input-inline">
                        <select name="typeId" lay-filter="typeId">
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">预警类型</label>
                    <div class="layui-input-inline">
                        <select name="type" lay-filter="type">
                            <option value="">全部</option>
                            <option value="1">低库存预警</option>
                            <option value="2">高库存预警</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">其他信息</label>
                    <div class="layui-input-inline" style="min-width: 200px;">
                        <input type="text" id="search" name="search" style="font-size: 12px;" placeholder="编号、名称、规格、备注" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <a class="layui-btn " lay-submit="" lay-filter="search" id="btn-search"><i class="layui-icon layui-icon-search"></i></a>
                </div>
            </div>
        </form>

        <div class="horizon-line"></div>

        <table class="layui-hide" id="table" lay-filter="table"></table>
    </div>
</div>

</body>
<html:loading/>
</html>